import util from "../../utils/util";
import {routerFilter} from '../../utils/routerFilter';
import Toast from '@vant/weapp/toast/toast';
routerFilter({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that=this;
    const eventChannel = that.getOpenerEventChannel();
    eventChannel.on('acceptDataFromOpenerPage', function(data) {
      that.setData(data);
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  refund(e) {
    let eycOrder = e.currentTarget.dataset.eycOrder;
    // let refundParams = {
    //     totalFee: 1/*eycOrder.price * 100*/,
    //     refundFee: 1,
    //     openid: eycOrder.openid,
    //     outTradeNo: eycOrder.orderNum,
    //     outRefundNo: eycOrder.orderId,
    //     opUserId: eycOrder.orderNum
    // };
    if(eycOrder.refundRemark){
      let that = this;
      util.promise('/applyRefund', eycOrder).then(res => {
        if (res.data) {
          Toast('订单退款申请已提交~');
          const eventChannel = that.getOpenerEventChannel();
          eventChannel.emit('refreshOrder');
          wx.navigateBack({ delta: 1 });
        }
      });
    }else{
      Toast('请填写退款申请原因~');
    }

  }
})